<?php
declare (strict_types = 1);

namespace app\caipu\controller;

use app\caipu\model\ConfigModel;
use app\caipu\model\IndexCaiLiaoModel;
use app\system\controller\Base;
use think\App;

class IndexCaiLiao extends Base
{
    private $model;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new IndexCaiLiaoModel();
    }

    /**
     * 列表
     */
    public function list(): \think\response\Json
    {
        $param = $this->request->param();
        $info = $this->model->paginate([
            'page'=>$param['pageNum'],
            'list_row'=>$param['pageSize']
        ])->toArray();

        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功',
            'rows'=> $info['data'],
            'total'=> $info['total']
        ];
        return json($returnData);
    }

    /**
     * 详细信息
     */
    public function getInfo($id): \think\response\Json
    {
        $info = $this->model->find($id)->toArray();
        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功',
            'data'=> $info
        ];
        return json($returnData);
    }

    /**
     * 新增通知公告
     */
    public function add()
    {
        $param = $this->request->param();
        $info = $this->model->save($param);
        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功'
        ];
        return json($returnData);
    }

    /**
     * 修改通知公告
     */
    public function edit()
    {
        $param = $this->request->param();
        $info = $this->model->save($param);
        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功'
        ];
        return json($returnData);
    }

    /**
     * 删除通知公告
     */
    public function remove($id)
    {
        $info = $this->model
            ->where('id', '=', $id)
            ->delete();
        $returnData = [
            'code'=> 200,
            'msg'=> '操作成功'
        ];
        return json($returnData);
    }
}
